package com.michi.okada.okdiary.view.listview;

import java.util.List;

import com.michi.okada.okdiary.R;
import com.michi.okada.okdiary.general.GlobalVariations;
import com.michi.okada.okdiary.general.Item;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class ItemListAdapter extends ArrayAdapter<Item> {
	private static class ViewHolder {
        int position;
        TextView textView;
    }
	
	private LayoutInflater mInflater;
	private Context mContext;
	
	private final static int LAYOUT_ID = R.layout.listview_item;
	
	public ItemListAdapter(Context context, List<Item> list) {
		super(context, LAYOUT_ID, list);
		mContext = context;
		this.mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			convertView = mInflater.inflate(this.LAYOUT_ID, null);
			holder = new ViewHolder();
			holder.textView = (TextView) convertView.findViewById(R.id.textviewListViewItem);
			//holder.textView.setOnClickListener(this);
			convertView.setTag(holder);
		} else {
            holder = (ViewHolder)convertView.getTag();
        }
		
		Item item = this.getItem(position);
		holder.position = position;
		
		holder.textView.setText(item.toShortString(40));
		
		return convertView;
	}

}
